#include <iostream>
using namespace std;

/*
	Rect r2=9+r1;
	  Rect r2=9.operator+(r1)  //成员理解，不行
	  Rect r2=operator+(9,r1)  //友元理解，正确
	 
	Rect r2=r1+9;  成员，友元都可以
	  Rect r2=r1.operator+(9);	
	  Rect r2=operator+(r1,9);	  
*/
class Rect
{
public:
	Rect(int _w=0,int _h=0)
	{
		w=_w;
		h=_h;
	}
/* 	Rect operator+(int n)
	{
		cout<<"成员函数Rect+int"<<endl;
		this->w=this->w+n;
		this->h=this->h+n;
		return *this;
	} */
	friend Rect operator+(Rect &other,int n);
private:
	int w;
	int h;
};

//普通函数
Rect operator+(Rect &other,int n)
{
	Rect temp;
	cout<<"普通函数Rect+int"<<endl;
	temp.w=other.w+n;
	temp.h=other.h+n;
	return temp;
} 

int main()
{
	Rect r1(12,5);
	//函数调用的写法，两者可以区分
	//operator+(r1,9);
	//r1.operator+(6);
	
	//人类习惯--》此时编译器转成函数调用，发现有两个答案，提示二义性
	Rect r2=r1+9;
	return 0;
}